#ifndef ConstraintIterator_H
#define ConstraintIterator_H

#include <iterator>

class Graph;

namespace SemanticModel
{
	template<typename TPointer>
	class ConstraintIterator : std::iterator<std::input_iterator_tag, int>
	{
	public:
		TPointer _p, _pEnd;
		const Graph* _g;
	public:

		typedef TPointer PointerType;

		ConstraintIterator(const Graph& g, TPointer p, TPointer pEnd)
			: _p(p), _pEnd(pEnd), _g(&g)
		{
		}

		ConstraintIterator& operator++()
		{
			++_p;
			check();
			return *this;
		}

		TPointer getPointer() const { return _p; } 

		bool operator==(const ConstraintIterator& rhs) { return equils(rhs); }

		bool operator!=(const ConstraintIterator& rhs) { return !equils(rhs); }

	protected:
		bool equils(const ConstraintIterator& rhs)
		{
			check();
			return _p == rhs._p;
		}

		void check()
		{
			if (_p != _pEnd && !test())
			{
				operator++();
			}
		}
		
		virtual const bool test() = 0;
	};
}

#endif // ConstraintIterator_H
